# Ruby学习网站
# https://www.ruby-lang.org/zh_cn/documentation/quickstart/3/
class Person


    attr_accessor :names

    def initialize(name = "jerry")
        @name = name
    end

    def say_hi
      if @names.nil?
        puts "names为空"
      elsif @names.respond_to?("each")
          @names.each do |name|
            puts "such #{name}"
          end
      else
        puts "hello #{@names}"
      end
    end
    def say_bye
        puts "bye #{@name}, come back soon"
    end
end

# __FILE__这个变量代表文件自己的文件名，在foo.rb中puts__FILE__，结果就是foo.rb；$0文件名

if __FILE__ == $0
    puts "-----------------------------"
    puts Person.instance_methods(false)
    puts Person.respond_to?("say_hi")
    puts Person.to_s
    puts Person
    person = Person.new
    person.say_hi
    person.say_bye

    puts "-----------------------------"
    person.names = ["tom","tony"]
    person.say_hi
end